C  The following routines generate error bars with open symbols.
C  Written by Igor Bray (1992)
      Subroutine erry(x,y,ybar,istart,istop,icode)

C  uses GHOST routines to plot vertical error bars on a graph.
C  If icode is zero or greater, a marker symbol is plotted at
C  each x,y point.

      Dimension x(istop),y(istop),ybar(istop)
      Dimension xtemp(2),ytemp(2)

      if(icode.ge.0) call ptplot(x,y,istart,istop,icode)
      do 10 i=istart,istop
         xtemp(1)=x(i)
         xtemp(2)=x(i)
         ytemp(1)=y(i)+ybar(i)
         ytemp(2)=y(i)-ybar(i)
         call getminmax(x(i),y(i),xmin,xmax,xminp,ymin,ymax,yminp)
         call mask(xmin,xmax,ymin,ymax)
         if (ybar(i).gt.y(i)-yminp) call ptgraf(xtemp,ytemp,1,2,45)
         call unmask(0)
10    continue
      return
      end

      Subroutine errx(x,y,xbar,istart,istop,icode)

C  uses GHOST routines to plot horizontal error bars on a graph.
C  If icode is zero or greater, a marker symbol is plotted at
C  each x,y point.

      Dimension x(istop),y(istop),xbar(istop)
      Dimension xtemp(2),ytemp(2)

      if(icode.ge.0) call ptplot(x,y,istart,istop,icode)
      do 10 i=istart,istop
         ytemp(1)=y(i)
         ytemp(2)=y(i)
         xtemp(1)=x(i)+xbar(i)
         xtemp(2)=x(i)-xbar(i)
         call getminmax(x(i),y(i),xmin,xmax,xminp,ymin,ymax,yminp)
         call mask(xmin,xmax,ymin,ymax)
         if (xbar(i).gt.x(i)-xminp) call ptgraf(xtemp,ytemp,1,2,192)
         call unmask(0)
10    continue
      return
      end

      Subroutine errxy(x,y,xbar,ybar,istart,istop,icode)
C  uses GHOST routines to plot both vertical and horizontal error
C  bars on a graph. If icode is zero or greater, a marker symbol
C  is plotted at each x,y point.

      Dimension x(istop),y(istop),ybar(istop),xbar(istop)
      Dimension xtemp(2),ytemp(2)

      if(icode.ge.0) call ptplot(x,y,istart,istop,icode)
      do 10 i=istart,istop
         xtemp(1)=x(i)
         xtemp(2)=x(i)
         ytemp(1)=y(i)+ybar(i)
         ytemp(2)=y(i)-ybar(i)
         call getminmax(x(i),y(i),xmin,xmax,xminp,ymin,ymax,yminp)
         call mask(xmin,xmax,ymin,ymax)
         if (ybar(i).gt.y(i)-yminp) call ptgraf(xtemp,ytemp,1,2,45)
         ytemp(1)=y(i)
         ytemp(2)=y(i)
         xtemp(1)=x(i)+xbar(i)
         xtemp(2)=x(i)-xbar(i)
         if (xbar(i).gt.x(i)-xminp) call ptgraf(xtemp,ytemp,1,2,192)
         call unmask(0)
10    continue
      return
      end

      subroutine getminmax(x,y,xmin,xmax,xminp,ymin,ymax,yminp)
      dimension idata(10),rdata(12)

C  get the magnification of the character
      call enqchr(idata,rdata)
      mag = idata(2)
C  The size in ND space of half the character
      size = mag * 0.001 / 7.0 * 4.0 / 2.0
C  Decide on the min span of error bars in order for them to be printed
      sizep = size * 1.5
C  Get the mappings
      call enqmap(idata,rdata)

      if (idata(1).le.2) then
         const = (rdata(2) - rdata(1)) / (rdata(10) - rdata(9)) 
         xmin = x - const * size 
         xminp = x - const * sizep
         xmax = x + const * size 
      else
         const = (log(rdata(2)) - log(rdata(1)))/(rdata(10) - rdata(9))
         xmin = x / exp(const * size)
         xminp = x / exp(const * sizep)
         xmax = x * exp(const * size)
      end if

      if (idata(1).eq.1.or.idata(1).eq.3) then
         const = (rdata(4) - rdata(3)) / (rdata(12) - rdata(11)) 
         ymin = y - const * size 
         yminp = y - const * sizep
         ymax = y + const * size 
      else
         const = (log(rdata(4)) - log(rdata(3)))/(rdata(12) - rdata(11))
         ymin = y / exp(const * size)
         yminp = y / exp(const * sizep)
         ymax = y * exp(const * size)
      end if
      end
      
